home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qlib205.zip / QLIB.ZIP / C / FONT.C < prev    next >
C/C++ Source or Header  |  1997-05-29  |  2KB  |  127 lines

  1. // Creates a simple font file (8*8)
  2.  
  3. // FIX : 32bit created properly now
  4. // NEW : mono-colored fonts 
  5.  
  6. #include <qlib.h>
  7. #include <string.h>
  8. #include <mem.h>
  9. #include <dos.h>
  10. #include <io.h>
  11. #include <conio.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <fCNTL.H>
  15.  
  16. int f;
  17. word a,x,y;
  18. dword p=0;
  19. byte buf[8*8*256*4];
  20. byte * vga=(byte *)0xa0000;
  21. byte flg=0;
  22. byte t;
  23. byte bypp,bpp;
  24.  
  25. struct
  26. {
  27.   byte head[4];
  28.   word x;
  29.   word y;
  30.   byte bpp;
  31.   byte bypp;
  32.   byte flg;
  33. } fnthead;
  34.  
  35. void usage(void)
  36. {
  37.   printf("Usage : FONT bypp outfile [/M] \n",a);
  38.   printf("  bypp = target bytes/pixel (8,15,16,24 or 32)\n");
  39.   printf("  /M = create mono-coloured font\n");
  40.   exit(0);
  41. }  
  42.  
  43. void main (byte _argc,byte **_args)
  44. {
  45.   if ((_argc<3)||(_argc>4)) usage();
  46.   bpp=atoi(_args[1]);
  47. //  printf("bpp=%d",bpp);
  48.   f=open(_args[2],O_BINARY|O_CREAT|O_TRUNC|O_WRONLY);
  49.   if (f==-1)
  50.   {
  51.     printf("file io error\n");
  52.     exit(0);
  53.   }
  54.  
  55.   if (bpp==8) bypp=1;
  56.   else if (bpp==15) bypp=2;
  57.   else if (bpp==16) bypp=2;
  58.   else if (bpp==24) bypp=3;
  59.   else if (bpp==32)
  60.   {
  61.     bypp=4;
  62.     flg=1;
  63.   }
  64.   else usage();
  65.  
  66.   strcpy(fnthead.head,"FNT");
  67.   fnthead.head[3]=0x1a;
  68.   fnthead.x=8;
  69.   fnthead.y=8;
  70.   fnthead.bpp=bpp;
  71.   fnthead.bypp=bypp;
  72.   fnthead.flg=0;
  73.   if (_argc==4)
  74.   {
  75.     if ( (!memcmp(_argv[3],"/M",2)) || (!memcmp(_argv[3],"/m",2)))
  76.     {
  77.       fnthead.flg=1;
  78. //      printf("Mono Font");
  79. //      getch();
  80.     }
  81.   }
  82.   write(f,&fnthead,sizeof(fnthead));
  83.   asm
  84.   {
  85.     mov ax,13h
  86.     int 10h
  87.   }
  88.  
  89.   if (bypp==4)
  90.   {
  91.     bypp--;
  92.     flg=1;
  93.   }
  94.   for (a=0;a<256;a++)
  95.   {
  96.     gotoxy(1,1);
  97.     if (a!=7) printf("%c",a); else printf(" ");
  98.     for(y=0;y<8;y++)
  99.     {
  100.       for(x=0;x<8;x++)
  101.       {
  102.         if (*(vga+y*320+x))
  103.         {
  104.           if (bypp==1) for(t=0;t<bypp;t++) buf[p++]=31;
  105.             else for(t=0;t<bypp;t++) buf[p++]=255;
  106.           if (flg) buf[p-1]=0;  //last byte in 32bit fonts
  107.         } else
  108.         {
  109.           for(t=0;t<bypp;t++) buf[p++]=0;
  110.         }
  111.       }
  112.     }
  113.   }
  114.   if (flg) bypp++;
  115.   asm
  116.   {
  117.     mov ax,3
  118.     int 16     //set text mode
  119.   }
  120.   write(f,buf,8*8*256*bypp);
  121.   close(f);
  122.   printf("done\n");
  123. }
  124.  
  125.  
  126.  
  127.